/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.util;

import model.dto.User;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author lab
 */
public class SharingUtil {

    public static final String VAR_A_CONNECTION_URL = "qz-a-connection-url";
    public static final String VAR_A_CONNECTION_POST = "qz-a-connection-post";
    public static final String VAR_A_DB_INSTANCE = "qz-a-db-instance";
    public static final String VAR_A_DB_DRIVER = "qz-a-db-driver";
    public static final String VAR_A_DB_USER = "qz-a-db-user";
    public static final String VAR_A_DB_PASSWORD = "q-z-a-db-password";
    public static final String VAR_A_MAIL_SERVER = "qz-a-mail-server";
    public static final String VAR_A_MAIL_PORT = "qz-a-mail-port";
    public static final String VAR_A_MAIL_USER_ID = "qz-a-mail-userid";
    public static final String VAR_A_MAIL_PASSWORD = "qz-a-mail-password";
    public static final String VAR_S_USER = "qz-s-user";
    public static final String VAR_S_MESSAGE = "qz-s-message";
    public static final String VAR_S_ADMIN_MESSAGE = "qz-s-admin-message";
    public static final String VAR_S_CLASS = "qz-s-class-id";
    public static final String VAR_S_EXAM = "qz-s-exam-id";

    public static void showMessage(javax.servlet.http.HttpServletRequest request, String message) {
        request.getSession().setAttribute(VAR_S_ADMIN_MESSAGE, message);
    }

    public static void showMessage(javax.servlet.http.HttpServletRequest request, ActionMessage message) {
        request.getSession().setAttribute(VAR_S_ADMIN_MESSAGE, message.toString());
    }

    public static void showMessage(javax.servlet.http.HttpSession session, String message) {
        session.setAttribute(VAR_S_ADMIN_MESSAGE, message);
    }

    public static User getUser(javax.servlet.http.HttpSession session) {
        Object obj = session.getAttribute(VAR_S_USER);
        User user = new User();
        if (obj != null) {
            user = (User) obj;
        }
        return user;
    }

    public static boolean isUserLoggedIn(User user) {
        if (user == null) {
            return false;
        }
        return !user.getUsername().equals("");
    }

    public static model.dto.Class getCurrentClass(javax.servlet.http.HttpSession session) {
        Object obj = session.getAttribute(VAR_S_CLASS);
        if (obj == null) {
            return new model.dto.Class();
        }
        return (model.dto.Class) obj;
    }

    public static model.dto.Exam getCurrentExam(javax.servlet.http.HttpSession session) {
        Object obj = session.getAttribute(VAR_S_EXAM);
        if (obj == null) {
            return new model.dto.Exam();
        }
        return (model.dto.Exam) obj;
    }

    public static void setCurrentClass(javax.servlet.http.HttpSession session, model.dto.Class cls) {
        session.setAttribute(VAR_S_CLASS, cls);
    }

    public static void setCurrentExam(javax.servlet.http.HttpSession session, model.dto.Exam exam) {
        session.setAttribute(VAR_S_EXAM, exam);
    }
}
